<template>
  <div class="client-content">
    <flexbox>
    <flexbox-item ><div class="flex-demo title">{{i.customerName}}<span>{{i.partnerName}}</span><span id="spanstatus">{{i.applyStatus | applystate}}</span></div></flexbox-item>
    <flexbox-item :span="3"><div class="flex-demo date">{{i.applyTime | datereserve}}</div></flexbox-item>
    </flexbox>
    <flexbox class="desc-content">
    <flexbox-item v-if="cpsShow"><div class="flex-demo">申请:<span>{{i.applyBalance}}元</span><span>{{i.applyTerm}}个月</span></div></flexbox-item>
    <flexbox-item v-if="!cpsShow"><div class="flex-demo">注册用户数:<span>{{i.applyCnt}}</span></div></flexbox-item>
    <flexbox-item><div class="flex-demo"><a @click.self.stop="relationclient"><img src="../../static/img/dianhua@2x.png" />联系客户</a></div></flexbox-item>
    </flexbox>
    <flexbox>
    <flexbox-item v-if="cpsShow">
      <div class="flex-demo" v-if="moneyshow">批复:<span>{{i.creditBalance}}元</span><span>{{i.creditTerm}}个月</span></div>
      <div class="flex-demo" v-if="!moneyshow">批复:<span>0元</span></div>
    </flexbox-item>
    <flexbox-item v-if="!cpsShow"><div class="flex-demo">放款用户数:<span>{{i.creditCnt}}</span></div></flexbox-item>
    <flexbox-item v-if="i.canfly === true"><div class="flex-demo" @click="Toplatform"><img src="../../static/img/zhuanran@2x.png" />转给平台</div></flexbox-item>
    </flexbox>
</div>
</template>
<script>
var timeStamp = String(Number(new Date()))
import api from '../api'
import utils from '../utils'
import { Flexbox, FlexboxItem } from 'vux'
export default {
  props: ['i'],
  data () {
    return {
      cpsShow: true,
      moneyshow: true
    }
  },
  components: {
    Flexbox,
    FlexboxItem
  },
  created () {
    this.tokenval = utils.AuthToken(timeStamp, this.$store.state.userkey)
    if (this.i.creditBalance && this.i.creditBalance !== 0) {
      this.moneyshow = true
    } else {
      this.moneyshow = false
    }
  },
  methods: {
    // 联系客户
    relationclient () {
      api.relocation({
        token: this.tokenval,
        timestamp: timeStamp,
        userId: this.$store.state.userID,
        fromType: 0,
        applyId: this.i.id
      }).then(res => {
        console.log(res)
        if (res.status === '200') {
          window.location.href = `tel:${res.data.mobile}`
        } else {
          this.$vux.toast.show({
            text: res.message,
            type: 'warn',
            width: '4rem'
          })
        }
      })
    },
    // 转给平台
    Toplatform () {
      var self = this
      api.feemessage({
        token: this.tokenval,
        timestamp: timeStamp,
        userId: this.$store.state.userID,
        id: this.i.id,
        fromType: 0,
        feeType: 0
      }).then(res => {
        console.log(res)
        this.$vux.confirm.show({
          content: '转让该客户，您将获得平台奖励' + res.data.transfer + '元，客户被购买后奖励立刻到账，同时您 将无该客户继续联系。是否转让？',
          confirmText: '确认转让',
          cancelText: '取消转让',
          onCancel () {
            console.log('plugin cancel')
          },
          onConfirm () {
            api.cession({
              token: self.tokenval,
              timestamp: timeStamp,
              userId: self.$store.state.userID,
              applyId: self.i.id
            }).then(res => {
              if (res.status === '200') {
                self.$router.push('/center/customer')
              } else {
                this.$vux.toast.show({
                  text: res.message,
                  type: 'warn',
                  width: '4rem'
                })
              }
            })
          }
        })
      })
    }
  }
}
</script>

